/**
 * 
 */
package com.dianba.supply.demo.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.springframework.stereotype.Service;

import com.dianba.commons.exception.core.AssertCore;
import com.dianba.commons.exception.lang.Assert;
import com.dianba.supply.demo.service.TestService;

/**
 *
 *
 * @author zhoucong
 * @date 2016年3月25日 下午5:52:22
 */
@Service
public class TestServiceImpl implements TestService {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dianba.demo.service.TestService#getNum(int)
	 */
	@Override
	public Integer getNum(int i) {
		AssertCore.G4004.isTrue(2 == i);

		return i++;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.dianba.demo.service.TestService#getStr(java.lang.String)
	 */
	@Override
	public String getStr(String type) {
		AssertCore.G4004.isTrue("1".equals(type), "未知的类型");
		Integer i = new Random().nextInt(10);
		for (int j = 0; j < i; j++) {
			type += i;
		}
		Assert.isTrue(type.length() < 8, AssertCore.G4005, "未知类型的东西", i);

		return type;
	}

	public void updatePwd(Integer userid, String pwd) {
		Map<String ,String> properties = find(userid);
		Assert.dataNotFound(properties);
		AssertCore.G7013.isTrue(properties.get("pwd").equals(pwd));
		// .. updae wpd ...
	}
	
	private Map<String ,String>  find(Integer userid){
		Map<String ,String> properties = new HashMap<>();
		if(userid==2){
			properties.put("pwd", "123123");
			return properties;
		}
		return null;

	}

}
